import logging
import requests
from api.login_api import Mepsking_Login
from config import Base_Host
class Cart_Api:
    def add_to_cart(self,json_dict,token):
        header_dict = {'accessToken': token}
        url=Base_Host+'/api/meps/cartItem/addToCart'
        resp=requests.post(url=url,json=json_dict,headers=header_dict)
        logging.info('购物车添加接口返回的数据为：{}'.format(resp.json()))
        return resp
    def del_To_cart(self,json_dict,token):
        header_dict = {'accessToken': token}
        url = Base_Host + '/api/meps/cartItem/addToCart'
        resp = requests.post(url=url, json=json_dict, headers=header_dict)
        logging.info('购物车删除接口返回的数据为：{}'.format(resp.json()))
        return resp
    def updata_To_cart(self,json_dict,token):
        header_dict = {'accessToken': token}
        url=Base_Host+'/api/meps/cartItem/updateToCart'
        resp=requests.post(url=url,json=json_dict,headers=header_dict)
        logging.info('购物车编辑接口返回的数据为：{}'.format(resp.json()))
        return resp
if __name__ == '__main__':
    resp = Mepsking_Login()
    login_json_dict = {"account": "2524726232@qq.com", "password": "8c730e7f3dac741443cd3a57cdb7fd8f", "sourceFrom": "PC"}
    token = resp.token(login_json_dict)
    cart=Cart_Api()
    json_dict={"cartCount":1,"skuId":"1628972386198597634","spuCode":"221010857654"}
    updata_dict={"skuId":"1628972386429284354","oldSkuId":"1628972386198597634","cartCount":1,"spuCode":"221010857654"}
    deleta_dict={"cartCount":1,"skuId":"1628972386198597634","spuCode":"221010857654"}
    # resp=cart.updata_To_cart(json_dict,token)
    # {"json_dict": {"skuId": "1628972386429284354", "cartCount": 1, "spuCode": "221010857654"}, "code": 200,
    # "result": true}
    # json_dict={"skuId":"1628972386429284354","oldSkuId":"1628972386198597634","cartCount":-21323,"spuCode":"221010857654"}
    resp=cart.del_To_cart(deleta_dict,token)

